package kislo.dima.task2;

import java.util.Random;

/**
 * *
 * @author Dima Kislo
 *
 */

public class Sort {

	public static void main(String[] args) {

		int m = Integer.parseInt(args[0]);
		int[] d = new int[m];
		for (int i = 0; i < m; i++)
			d[i] = new Random().nextInt(100);

		System.out.print("Default array:");
		for (int row : d) {
			System.out.print(row + " ");
		}
		System.out.println();

		if (args[1].equals("up"))
			SortUp(d, m);
		else if (args[1].equals("down"))
			SortDown(d, m);

		System.out.print("Sort array:");
		for (int row : d) {
			System.out.print(row + " ");
		}
		System.out.println();
	}

	public static void SortUp(int[] d, int m) {
		boolean flag = true;
		while (flag) {
			m = m - 1;
			flag = false;
			for (int i = 0; i < m; i++) {
				if (d[i] > d[i + 1]) {
					int temp = d[i];
					d[i] = d[i + 1];
					d[i + 1] = temp;
					flag = true;
				}
			}
		}
	}

	public static void SortDown(int[] d, int m) {
		boolean flag = true;
		while (flag) {
			m = m - 1;
			flag = false;
			for (int i = 0; i < m; i++) {
				if (d[i] < d[i + 1]) {
					int temp = d[i];
					d[i] = d[i + 1];
					d[i + 1] = temp;
					flag = true;
				}
			}
		}
	}

}
